import { watch, ref } from 'vue'
import { post } from '@/utils/request'
/**
 * @name 获取患者信息
 * @param {string} id 住院号
 * @param {string} type 门诊/住院
 */
export default function (id, type) {
  const patientInfo = ref({})
  //获取住院患者信息
  const getInpatientInfo = async () => {
    const { data, code } = await post('/inp/zydj/getInpRecordInfo', { zybh: id.value })
    if (code === 0) {
      patientInfo.value = data
    }
  }
  //获取门诊患者信息
  const getOutpatientInfo = async () => {
    const { data, code } = await post('/outp/mzys/getOutpRecordInfo', { mzjlbh: id.value })
    if (code === 0) {
      patientInfo.value = data
    }
  }
  watch(id, (val) => {
    if (val) {
      type === '门诊' ? getOutpatientInfo() : getInpatientInfo()
    }
  })

  return patientInfo
}
